package top.z.work.framework.auth.config;

import cn.dev33.satoken.stp.StpInterface;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import top.z.work.module.system.api.authorize.AuthorizeServiceApi;

import java.util.List;

@Slf4j
@Component
public class SaTokenConfig implements StpInterface {

    @Resource
    private AuthorizeServiceApi authorizeServiceApi;

    /**
     * 返回指定账号id所拥有的权限码集合
     *
     * @param loginId   账号id
     * @param loginType 账号类型
     * @return 该账号id具有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return authorizeServiceApi.permissionList(Long.parseLong(loginId.toString()));
    }

    /**
     * 返回指定账号id所拥有的角色标识集合
     *
     * @param loginId   账号id
     * @param loginType 账号类型
     * @return 该账号id具有的角色标识集合
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        return authorizeServiceApi.roleList(Long.parseLong(loginId.toString()));
    }
}
